package cn.lee.cplibrary.init;

import static cn.lee.cplibrary.init.CPSignatureUtil.isValidSignatureHex;

import android.content.Context;

import cn.lee.cplibrary.util.LogUtil;

/**
 * 使用CPLibrary，需要在该项目的Application中配置CPSDKInitializer.initialize()，
 * 来验证工具库是否支持该项目调用，若不配置，则会运行异常
 */
public class CPInitializer {

    // 初始化标志
    private static boolean isInitialized = false;

    public static void initialize(Context context) {
        if (!isValidSignatureHex(context)) {
            throw new SecurityException("This CPSDK can only be used with the target application.");
        }
        isInitialized = true;
        LogUtil.d("", "CPSDK initialized successfully.");
    }

    public static void checkInitialization() {
        if (!isInitialized) {
            throw new IllegalStateException("CPSDK must be initialized before using its methods.");
        }
    }
}